#include <iostream>
#include <vector>
using namespace std;


int max_sum_recur(vector<vector<int>> &nums, int n, int m, vector<vector<int>> &recd)
{
        if(n == nums.size()){
                return 0;
        }
        if(recd[n][m] != -1){
                return recd[n][m];
        }

        return recd[n][m] = max(max_sum_recur(nums, n + 1, m, recd), max_sum_recur(nums, n + 1, m + 1, recd)) + nums[n][m];
}

int max_sum_dp(vector<vector<int>> &nums)
{
        int n = nums.size();
        vector<int> dp(n + 1, 0);

        for(int i = n - 1; i >= 0; i--){
                for(int j = 0; j <= i; j++){
                        dp[j] = max(dp[j], dp[j + 1]) + nums[i][j]; 
                }
        }

        return dp[0];
}

int main()
{
        int n = 0;
        cin>>n;

        vector<vector<int>> nums(n, vector<int>(n, 0));
        vector<vector<int>> recd(n, vector<int>(n, -1));
        for(int i = 0; i < n; i++){
                for(int j = 0; j <= i; j++){
                        cin>>nums[i][j];
                }
        }

        //cout<<max_sum_recur(nums, 0, 0, recd)<<endl;
        cout<<max_sum_dp(nums)<<endl;

        return 0;
}